/**
 *     This file is part of cesm-ws.
 *
 *     cesm-ws, Web Service for Community Earth System Model
 *
 *     Copyright (c) 2010, Purdue University and/or affilicates or thrid-party contributors as
 *     indicated by the @author tags or express copyright attribution statements
 *     applied by the authors. All third-party contributions are distributed under
 *     license by Purdue University.
 *
 *     cesm-ws is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with this distribution.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.purdue.rcac.service.dispatch;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;

import javax.activation.DataHandler;

import org.globus.ftp.exception.FTPException;
import org.jboss.ejb3.annotation.Management;

import bsh.EvalError;
import edu.purdue.rcac.grid.submit.SubmissionException;
import edu.purdue.rcac.grid.submit.Submitter;

/**
 * {@link ServiceDispatcher} management interface
 * 
 * @author Han Zhang
 * 
 */
@Management
public interface ServiceDispatcherManagement {

	public static String OBJECT_NAME = "service.dispatch:service=ServiceDispatcher";

	public enum SubmitType {
		GLOBUS, CONDOR
	};

	public enum SubmitterImpLanguage {
		JAVA, BEAN_SHELL
	}

	public enum AuthDatabase {
		PortalDB, MyProxy
	}

	void create() throws Exception;

	void start() throws Exception;

	void stop();

	void destroy();

	public boolean registerApp(String appName,
			SubmitterImpLanguage submitterImpLang, SubmitType submitType);

	public String generateToken(String userName, String password,
			AuthDatabase database);

	public void renewToken(String userName, String token);

	public boolean verifyToken(String userName, String token);

	/**
	 * submit a job with given argument map
	 * 
	 * @param appName
	 *            name of application
	 * @param submitType
	 *            {@link SubmitType} enum value
	 * @param submitterLanguage
	 *            {@link SubmitterImpLanguage} enum value, indicates the
	 *            implementation language of submitter
	 * @param argsMap
	 *            argument map
	 * @return {@link ServiceResponse} object that contains result of this
	 *         submission
	 * @throws SubmissionException
	 */
	public ServiceResponse submit(String appName, Map<String, String> argsMap)
			throws IllegalArgumentException, InstantiationException,
			SubmissionException;

	public ServiceResponse upload(String appName, Map<String, String> argsMap,
			String toPath, DataHandler data) throws IOException,
			InstantiationException;

	public DataHandler download(String appName, Map<String, String> argsMap,
			String fromPath) throws IOException, InstantiationException;

	public String getFileContent(String appName, Map<String, String> argsMap)
			throws IOException, InstantiationException;
}
